CPP

source Code Mini Game CPP ’Tebak Kata’

I got email to request my Mini Game CPlusPlus ’Tebak Kata’ from Mr. Taufan Hidayatullah.. Hope can useful 4 u.. ^_^ Take Enjoy your Practice dude.. Check This Out..

/* ** Author : Yupi Sugianto S.Kom ** Language : C++ ** Compiler : Borland CPP ** email : ups_in_blues@yahoo.com ** website : http://www.yupisugianto.com */ #include<constream.h> #include<iostream.h> #include<string.h> #include<time.h> #include<stdlib.h> #include<ctype.h> #include<stdio.h> constream out; class data { private : char kata[15]; char hint[25]; public : data(char *,char* ); char * getKata(); char * getHint(); void setKata(char *); }; void data::setKata(char *namanya) { strcpy(this->kata,namanya); } data::data(char *kta,char*hnt) { strcpy(this->kata,kta); strcpy(this->hint,hnt); } char * data::getKata() { return kata; } char * data::getHint() { return hint; } void tampilan(int *flag); void upChose(void); void downChose(void); void gambar(int nyawa); void initData(int level); void pilihLv(int *flagLv); void allHuruf(void); void judul(); int cekTebak(char value,int kt); int maxTebak=0; char ketebak[15]; char tbkHuruf[25]; int maxTbkHuruf=0; data *dat[10]; void main() { randomize(); int flag; int flagLv; int nyawa; char tekan; textmode(C80); while(1) { tampilan(&flag); if(flag==0) { out<<setbk(0); out.clrscr(); pilihLv(&flagLv); nyawa=5; tekan=NULL; initData(flagLv); char CurrKata[15]; char CurrHint[25]; int kt = random(200)%9; char tbkLangsung[15]; strcpy(CurrKata,dat[kt]->getKata()); strcpy(CurrHint,dat[kt]->getHint()); int len = strlen(CurrKata); maxTebak=0; maxTbkHuruf=0; for(int i=0;i<10;i++)ketebak[i]=NULL; int len2=0; // kalo uda sama ama len maka udah ketebak semua while(tekan!=’3’) { gambar(nyawa); allHuruf(); judul(); out<<setxy(22,8)<<"HINT : "<<CurrHint; out<<setxy(22,10); len2=0; // untuk pengecekan menang. set 0 dulu for(i=0;i<len;i++) { int pketebak=0; for(int j =0;j<maxTbkHuruf;j++) { if(CurrKata[i]==ketebak[j]) { pketebak=1; } } if(pketebak==1) { len2++; // kalo udah sama ama len maka menang out<<CurrKata[i]<<" "; } else if(pketebak==0) { out<<" "; } } out<<setxy(22,11); char space = ’ ’; for(i =0;i<len;i++) { //out<<CurrKata[i]<<" "; if(CurrKata[i]!=space) { out<<(char)196<<" "; } else if(CurrKata[i]==space) { out<<" "; } } out<<setxy(15,17)<<setclr(2)<<" -=MENU=- "; out<<setxy(15,18)<<setclr(15)<<"1. Tebak Huruf"; out<<setxy(15,19)<<"2. Tebak Kata "; out<<setxy(15,20)<<"3. Keluar "; out<<setxy(15,21)<<"PILIH ? ";   if(len2==len || strcmp(CurrKata,tbkLangsung)==0) { if(strcmp(CurrKata,tbkLangsung)==0) { out<<setxy(22,10); for(int i =0;i<strlen(CurrKata);i++) { out<<CurrKata[i]<<" "; } } out<<setxy(23,21)<<setclr(14+128)<<"You WON! Press Any Key To back to Menu."; getch(); break; } if(nyawa==0) { out<<setxy(23,21)<<setclr(4+128)<<"You LOSE! Press Any Key To back to Menu."; getch(); break; } cin.sync(); cin.clear(); tekan=getch(); switch(tekan){ case ’1’: char tbk; out<<setxy(30,18)<<"-> Tebakan Huruf ? "; cin>>tbk; cin.sync(); cin.clear(); tbk=toupper(tbk); if(cekTebak(tbk,kt)==1) { ketebak[maxTbkHuruf]=tbk; maxTbkHuruf++; // maksimal tebakan huruf yang berhasil } else if(cekTebak(tbk,kt)==0) { nyawa--; } tbkHuruf[maxTebak]=tbk; maxTebak++; // maksimal tebakan user, termasuk yang gagal break; case ’2’: out<<setxy(30,19)<<"-> Tebakan Langsung ? "; cin.getline(tbkLangsung,15); cin.sync(); cin.clear(); // jadiin huruf besar semua for(int i=0;i<strlen(tbkLangsung);i++) { tbkLangsung[i] = toupper(tbkLangsung[i]); } //kalo salah nyawa kurang if(strcmp(CurrKata,tbkLangsung)!=0) { nyawa--; } break; } } } else if(flag==1)break; } } //===================================================== void initData(int level) { if(level==0) // easy { dat[0] = new data("MONITOR","output komputer"); dat[1] = new data("KEYBOARD","input komputer"); dat[2] = new data("PARFUM","wangi baunya"); dat[3] = new data("SPEAKER","kotak bersuara"); dat[4] = new data("KERTAS","dapat ditulis"); dat[5] = new data("PIRING","untuk makan"); dat[6] = new data("SENDOK","kluar masuk mulut"); dat[7] = new data("HARIMAU","binatang buas"); dat[8] = new data("MINGGU","week end"); dat[9] = new data("POSTER","biasa dipajang"); } else if(level==1) // hard { dat[0] = new data("PROCESOR","otak komputer"); dat[1] = new data("BAJAKAN","seperti kriminal"); dat[2] = new data("LEMARI","dekat ranjang"); dat[3] = new data("VIDEO GAMES","make you happy"); dat[4] = new data("PETAK UMPAT","kids game"); dat[5] = new data("HOME ALONE","film Natal"); dat[6] = new data("BON JOVI","band"); dat[7] = new data("PELAUT","di laut"); dat[8] = new data("ARLOJI","terletak di tangan"); dat[9] = new data("PORCHE","car"); } } //===================================================== void gambar(int nyawa) { out<<setbk(0); out.clrscr(); _setcursortype(0); char a=219,b=186,c=201,d=184,e=205; char f=2,g=179,h=1; out<<setclr(15);   if(nyawa<5){ out<<setxy(14,9) <<f; // kepala } if(nyawa<4){ out<<setxy(14,10)<<g; // badan } if(nyawa<3){ out<<setxy(13,10)<<"/";// tangan kiri } if(nyawa<2){ out<<setxy(15,10)<<"\";//tangan kanan } if(nyawa<1){ out<<setxy(14,9) <<h; // kepala die out<<setxy(13,11)<<"/"; //kaki kiri out<<setxy(15,11)<<"\";//kaki kanan } //-------- out<<setxy(14,8) <<d; out<<setxy(13,8) <<e; out<<setxy(12,8) <<e; out<<setxy(11,8) <<c; out<<setxy(11,9) <<b; out<<setxy(11,10)<<b; out<<setxy(7,11)<<a<<a<<a<<a<<a; out<<setxy(5,12)<<a<<a<<a<<a<<a<<a<<a; } //========================================================= void tampilan(int *flag) { char tekan; out<<setbk(0); out.clrscr(); judul(); upChose(); out<<setxy(35,7)<<setclr(4)<<setbk(15)<<"NEW GAME"; out<<setxy(35,8)<<setclr(4)<<setbk(0)<<" EXIT "; *flag = 0; while(tekan!=13) { _setcursortype(0); tekan=getch(); if(tekan == 72) { if(*flag == 0) { downChose(); out<<setxy(35,7)<<setclr(4)<<setbk(0)<<"NEW GAME"; out<<setxy(35,8)<<setclr(4)<<setbk(15)<<" EXIT "; *flag = 1; } else if(*flag == 1) { upChose(); out<<setxy(35,7)<<setclr(4)<<setbk(15)<<"NEW GAME"; out<<setxy(35,8)<<setclr(4)<<setbk(0)<<" EXIT "; *flag = 0; } } else if(tekan == 80) { if(*flag == 0) { downChose(); out<<setxy(35,7)<<setclr(4)<<setbk(0)<<"NEW GAME"; out<<setxy(35,8)<<setclr(4)<<setbk(15)<<" EXIT "; *flag = 1; } else if(*flag == 1) { upChose(); out<<setxy(35,7)<<setclr(4)<<setbk(15)<<"NEW GAME"; out<<setxy(35,8)<<setclr(4)<<setbk(0)<<" EXIT "; *flag = 0; } } } } //=============================================================== void pilihLv(int *flagLv) { char tekan; out<<setbk(0); out.clrscr(); judul(); out<<setxy(30,5)<<setclr(2+128)<<" TINGKAT KESULITAN? "; upChose(); out<<setxy(35,7)<<setclr(4)<<setbk(15)<<" EASY "; out<<setxy(35,8)<<setclr(4)<<setbk(0)<< " NORMAL "; *flagLv = 0; while(tekan!=13) { _setcursortype(0); //out<<*flagLv; tekan=getch(); if(tekan == 72) { if(*flagLv == 0) { downChose(); out<<setxy(35,7)<<setclr(4)<<setbk(0)<<" EASY "; out<<setxy(35,8)<<setclr(4)<<setbk(15)<<" NORMAL "; *flagLv = 1; } else if(*flagLv == 1) { upChose(); out<<setxy(35,7)<<setclr(4)<<setbk(15)<<" EASY "; out<<setxy(35,8)<<setclr(4)<<setbk(0)<<" NORMAL "; *flagLv = 0; } } else if(tekan == 80) { if(*flagLv == 0) { downChose(); out<<setxy(35,7)<<setclr(4)<<setbk(0)<<" EASY "; out<<setxy(35,8)<<setclr(4)<<setbk(15)<<" NORMAL "; *flagLv = 1; } else if(*flagLv == 1) { upChose(); out<<setxy(35,7)<<setclr(4)<<setbk(15)<<" EASY "; out<<setxy(35,8)<<setclr(4)<<setbk(0)<<" NORMAL "; *flagLv = 0; } } } } //================================================================ void upChose() { out<<setxy(33,7)<<setclr(15)<<setbk(0)<<">>"; out<<setxy(43,7)<<setclr(15)<<setbk(0)<<"<<"; out<<setxy(33,8)<<setclr(15)<<setbk(0)<<" "; out<<setxy(43,8)<<setclr(15)<<setbk(0)<<" "; } //================================================================ void downChose() { out<<setxy(33,8)<<setclr(15)<<setbk(0)<<">>"; out<<setxy(43,8)<<setclr(15)<<setbk(0)<<"<<"; out<<setxy(33,7)<<setclr(15)<<setbk(0)<<" "; out<<setxy(43,7)<<setclr(15)<<setbk(0)<<" "; } //================================================================ void allHuruf() { out<<setbk(0); out<<setxy(15,15); for(int i=65;i<=90;i++) { char x=i; int cek=0; for(int j=0;j<maxTebak;j++) { if(x==tbkHuruf[j]) { cek=1; } } if(cek==1) { out<<setclr(RED)<<x<<" "; } else if(cek==0) { out<<setclr(15)<<x<<" "; } } } //================================================================= void judul() { out<<setbk(0); out<<setxy(30,4)<<setclr(15)<< "-= "TEBAK KATA "=-"; } //================================================================= int cekTebak(char value,int kt) { out<<setbk(0); for(int i=0;i<strlen(dat[kt]->getKata());i++) { if(dat[kt]->getKata()[i]==value){ return 1; } } return 0; }

You can Download Here Download Mini Game CPP ’Tebak Kata’ By Yupi Sugianto

Best Regards,

Yupi Sugianto, S.Kom



Related posts

Leave a Comment